package com.thinkingcoder.tccache.core.command.list;

import static com.thinkingcoder.tccache.constant.CommandConstants.ListCmd.LRANGE;

import com.thinkingcoder.tccache.core.command.Command;
import com.thinkingcoder.tccache.core.model.Reply;
import com.thinkingcoder.tccache.core.TcCache;

/**
 * LRANGE command.
 */
public class LRangeCmd implements Command {
    @Override
    public String name() {
        return LRANGE;
    }

    @Override
    public Reply<?> exec(TcCache cache, String[] args) {
        String key = getKey(args);
        String[] params = getParamsNoKey(args);
        int startIndex = Integer.parseInt(params[0]);
        int endIndex = Integer.parseInt(params[1]);
        return Reply.array(cache.lRange(key, startIndex, endIndex));
    }
}
